package com.ruoyi.common.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.List;

// 将String 转double 保留两位小数

public class CustomerDoubleSerialize extends JsonSerializer {

    private DecimalFormat df = new DecimalFormat("0.00");

    @Override
    public void serialize(Object arg0, JsonGenerator arg1, SerializerProvider arg2) throws IOException {
        String arg = arg0.toString();
        if(arg != null && !arg.equals("-")) {

            Double dd=Double.parseDouble(arg);

            arg1.writeString(df.format(dd));

        } else{

            arg1.writeString(arg);

        }

    }
}
